﻿namespace Digitalmes.Application.Sys.Dicts.Commands;

/// <summary>
/// 更新字典命令。
/// </summary>
/// <param name="Dict"></param>
public record UpdateDictCommand(SysDictDto Dict) : IRequest<IResult<bool>>;

internal sealed class UpdateDictCommandHandler(IRepository<SysDict> repo) : IRequestHandler<UpdateDictCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateDictCommand request, CancellationToken cancellationToken)
    {
        var dict = request.Dict.Adapt<SysDict>();
        var ok = await repo.UpdateAsync(dict, m => new {
            m.Name,
            m.Status,
            m.UpdatedBy,
            m.UpdatedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
